#!/usr/bin/env python3
#error.py

import sys
sys.path.insert(0, r'/home/george/Projects/ISH')
import dialog
from gi.repository import Gtk

class Handler:
    # Exit app if windows is closed. Traps the signal from GUI.
    def on_window_error_destroy(self, *args):
        Gtk.main_quit(*args)

    # Exit app if abort
    def on_window_error_esc_pressed(self, abort):
        Gtk.main_quit(abort)
        
    def on_window_error_ok_pressed(self, ok):
        start = self.textbuffer.get_start_iter()
        end = self.textbuffer.get_end_iter()
        text = self.textbuffer.get_text(start, end, include_hidden_chars = False)
        print (text)
        Gtk.main_quit()
    def __init__(self):
        '''Initialization of Handler class.
        
        We use the initialization of the Handler class to establish
        references to the widgets we'll need to work with in the callbacks for
        various signals. This is done using the XML file we created with Glade.
        '''   
        # Use GtkBuilder to build our interface from the XML file 
        try:
            builder = Gtk.Builder()
            builder.add_from_file("error.glade") 
        except:
            dialog.error_message("Failed to load UI XML file: error.glade")
            sys.exit(1)        
        
        # get the widgets which will be referenced in callbacks
        self.window_error = builder.get_object("window_error")
        self.textview = builder.get_object("textview")
        
        # Set up the textbuffer
        self.textbuffer = self.textview.get_buffer()
        self.textbuffer.set_text("")
#        self.textview.set_wrap_mode(Gtk.WrapMode.WORD)

        builder.connect_signals(self)

    # Run main application window
    def main(self):
        # Exit app if main win is closed (x:ed). Even if signal from GUI is missing.
        self.window_error.connect("delete-event", Gtk.main_quit)
        self.window_error.show()
        Gtk.main()
    
if __name__ == "__main__":
    error = Handler()
    error.main()
